<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
{{template "common/link.html" .}}
</head>
<body>
{{template "common/head.html" .}}
<div class="banner">
    <div class="cont w1000">
        <div class="title">
            <h3>MY<br/>BLOG</h3>
            <h4>well-balanced heart</h4>
        </div>
        <div class="amount">
            <p><span class="text">访问量</span><span class="access">1000</span></p>
            <p><span class="text">日志</span><span class="daily-record">1000</span></p>
        </div>
    </div>
</div>
<div class="cont w1000">
    <blockquote class="layui-elem-quote" style="overflow:hidden;margin: 20px 0px">
        <h3 class="float_left" style="line-height: 28px;">添加文章</h3>
    </blockquote>
    <div class="layui-row layui-row" style="margin: 20px 0">
        <div class="layui-card border-light-around layui-card-body" style="border: 1px solid #e6e6e6;">
            <form class="layui-form" action="" method="post">
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width:auto ">文章标题</label>
                    <div class="layui-input-block">
                        <input type="text" name="title" required lay-verify="required" placeholder="请输入标题"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width:auto ">文章内容</label>
                    <div class="layui-input-block ">
                        <div id="editor"></div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary ">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

{{template "common/foot.html"}}
<script type="text/javascript">
    layui.use(['jquery', 'form'], function () {
        var $ = layui.jquery,
                form = layui.form;

        var E = window.wangEditor;
        var editor = new E('#editor');
        editor.customConfig.pasteFilterStyle = false;//关闭粘贴样式的过滤
        editor.customConfig.zIndex = 1;//配置编辑区域的 z-index
        editor.customConfig.uploadImgShowBase64 = true   // 使用 base64 保存图片
        editor.create();

        form.on('submit(formDemo)',function (dataForm) {
            dataForm.field.content = editor.txt.html();
            $.post("/notes/save/{{.key}}",dataForm.field,function (res) {
                if(res.code==0){
                    layer.msg("添加成功！")
                    if (res.action){
                        setTimeout(function () {
                            window.location.href=res.action;
                        },3000)
                    }
                }else{
                    layer.msg("添加失败！"+res.msg);
                }
            },"json").error(function () {
                layer.msg("网络异常！")
            });
            return false;
        });
    })
</script>
</body>
</html>